package com.xiaoyu.client.ui.activity.main.mine.my_order;

import android.app.Dialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xiaoyu.client.R;
import com.xiaoyu.commonlib.ui.base.BaseActivityWithTitle;
import com.xiaoyu.commonlib.ui.dialog.ButtomDialogView;
import com.xiaoyu.commonlib.utils.ToastUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author jx
 * @date 创建时间 2018/10/24
 * @Description 选择服务类型2
 */
public class SelectServiceTypeTwoActivity extends BaseActivityWithTitle {

    @BindView(R.id.state_good_txt)
    TextView mStateGoodTxt;

    @BindView(R.id.activity_select_service_type_txt_refund_reason)
    TextView mRefundReasonTxt;

    private int statusGood = 0;//0：请选择 1：未收到货 2：已收到货
    private int refundReason = 0;//0：请选择 1：快递一直未到 2：未按照时间约定 3：空包裹/少货 4：其他

    @Override
    protected void loadContentView(ViewGroup parent) {
        setTitleText("选择服务类型");
        View mView = LayoutInflater.from(this).inflate(R.layout.activity_select_service_type_two, parent, true);
        ButterKnife.bind(this);
    }

    @OnClick(R.id.state_of_goods)//货物状态
    public void stateGoodClick() {
        ButtomDialogView dialogView = new ButtomDialogView(this, R.layout.state_of_good_item, true, true);
        dialogView.setOnTxtClickListener(onGoodTxtClickListener);
        dialogView.show();
    }

    @OnClick(R.id.a_refund_reason)//退款原因
    public void refundReasonClick() {
        ButtomDialogView dialogView = new ButtomDialogView(this, R.layout.a_refund_reason_item, true, true);
        dialogView.setOnTxtClickListener(onRefundTxtClickListener);
        dialogView.show();

    }


    /**
     * 货物状态dialog监听
     */
    private ButtomDialogView.OnTxtClickListener onGoodTxtClickListener = new ButtomDialogView.OnTxtClickListener() {
        @Override
        public void setOnClick(final Dialog dialog) {
            RelativeLayout unReceiveLayout = dialog.findViewById(R.id.not_yet_received_the_goods);
            RelativeLayout receiveLayout = dialog.findViewById(R.id.have_received_the_goods);
            CheckBox unReceive = dialog.findViewById(R.id.not_yet_received_the_goods_check_box);
            CheckBox receive = dialog.findViewById(R.id.have_received_the_goods_check_box);
            if (statusGood == 2){//已收到货
                receive.setChecked(true);
                unReceive.setChecked(false);
            }else {
                receive.setChecked(false);
                unReceive.setChecked(true);
            }

            unReceiveLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    mStateGoodTxt.setText("未收到货");
                    statusGood = 1;
                }
            });

            receiveLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mStateGoodTxt.setText("已收到货");
                    statusGood = 2;
                    dialog.dismiss();
                }
            });

        }
    };


    /**
     * 货物状态dialog监听
     */
    private ButtomDialogView.OnTxtClickListener onRefundTxtClickListener = new ButtomDialogView.OnTxtClickListener() {
        @Override
        public void setOnClick(final Dialog dialog) {
            RelativeLayout unArrivedLayout = dialog.findViewById(R.id.not_yet_arrived_the_express);
            RelativeLayout unFollowLayout = dialog.findViewById(R.id.not_follow_time_contract);
            RelativeLayout loseLayout = dialog.findViewById(R.id.empty_parcel_or_lose_goods);
            RelativeLayout otherLayout = dialog.findViewById(R.id.other_refund_reason);
            CheckBox unArrivedBox = dialog.findViewById(R.id.not_yet_arrived_the_express_check_box);
            CheckBox unFollowBox = dialog.findViewById(R.id.not_follow_time_contract_check_box);
            CheckBox loseBox = dialog.findViewById(R.id.empty_parcel_or_lose_goods_check_box);
            CheckBox otherBox = dialog.findViewById(R.id.other_refund_reason_check_box);
            if (refundReason == 4){//其他
                unArrivedBox.setChecked(false);
                unFollowBox.setChecked(false);
                loseBox.setChecked(false);
                otherBox.setChecked(true);
            }else if (refundReason == 3){//空包裹/少货
                unArrivedBox.setChecked(false);
                unFollowBox.setChecked(false);
                loseBox.setChecked(true);
                otherBox.setChecked(false);
            }else if (refundReason == 2){//未按照时间约定
                unArrivedBox.setChecked(false);
                unFollowBox.setChecked(true);
                loseBox.setChecked(false);
                otherBox.setChecked(false);
            }else {//快递一直未到
                unArrivedBox.setChecked(true);
                unFollowBox.setChecked(false);
                loseBox.setChecked(false);
                otherBox.setChecked(false);
            }

            unArrivedLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    mRefundReasonTxt.setText("快递一直未到");
                    refundReason = 1;
                }
            });

            unFollowLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    mRefundReasonTxt.setText("未按照时间约定");
                    refundReason = 2;
                }
            });

            loseLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    mRefundReasonTxt.setText("空包裹/少货");
                    refundReason = 3;
                }
            });

            otherLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    mRefundReasonTxt.setText("其他");
                    refundReason = 4;
                }
            });

        }
    };



}
